#include<course_management.h>
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<log.h>

Course read_course(int flag)
{
	if(flag)
		printf("Input Course infomation(num,name,attribute,credit_hour,credit_point,chosen_num,max_chosen_num)\n");
	std::string tnum,tname,tattribute;
	int credit_hour,credit_point,chosen_num,max_chosen_num;
	std::cin>>tnum>>tname>>tattribute>>credit_hour>>credit_point>>chosen_num>>max_chosen_num;

	Log("read course num:%s\n",tnum.c_str());

	Course res(tnum,tname,tattribute,credit_hour,credit_point,chosen_num,max_chosen_num);
	
	return res;

}

void Course_management::add_info(Course new_course)
{
	this->courses.push_back(new_course);
	score[new_course.num]=new_course.credit_point;
}

void Course_management::del_info(const std::string &num)
{
	for(int i=0;i<this->courses.size();++i)
		if(this->courses[i].num==num)
		{
			std::swap(this->courses[i],this->courses[this->courses.size()-1]);
			Log("delete course num:%s\n",this->courses[i].num.c_str());
			score[this->courses[i].num]=0,this->courses.pop_back();
		}
}

void Course_management::mod_info(const std::string &num)
{
	int mod_num=this->courses.size()-1;
	for(int i=0;i<this->courses.size();++i)
		if(this->courses[i].num==num)
		{
			std::swap(this->courses[i],this->courses[this->courses.size()-1]);
			Log("modify course num:%s\n",this->courses[i].num.c_str());
			score[this->courses[i].num]=0,this->courses.pop_back();
		}
	this->add_info(read_course(1));
}

void Course_management::check_info(const std::string &num)
{
	for(int i=0;i<this->courses.size();++i)
		if(this->courses[i].num==num)
			printf("num:%s\nname:%s\nattribute:%s\ncredit_hour:%d\ncredit_point:%d\nchosen_num:%d\nmax_chosen_num:%d\n\n",
			this->courses[i].num.c_str(),this->courses[i].name.c_str(),this->courses[i].attribute.c_str(),
			this->courses[i].credit_hour,this->courses[i].credit_point,
			this->courses[i].chosen_num,this->courses[i].max_chosen_num);

}
